<template>
  <div class="sdfb">
    <div class="head">
      <!-- <span class="title">手动分班</span> -->
      <div class="type">
        <span>类<span class="bank16"></span>别：</span>
        <el-select v-model="jhlb" filterable placeholder="请选择" disabled>
          <el-option
            v-for="item in jhlbs"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div class="kl">
        <span>科<span class="bank16"></span>类：</span>
        <el-select v-model="kl" filterable placeholder="请选择" disabled>
          <el-option
            v-for="item in kls"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div class="major">
        <span>专<span class="bank16"></span>业：</span>
        <el-input v-model="zymc" placeholder="请输入内容"></el-input>
      </div>

      <button @click="query">查询</button>
      <button @click="reset">重置</button>

      <!-- <div class="yuanxi">
        <span>选择院系：</span>
        <el-select v-model="yx" filterable placeholder="请选择" disabled>
          <el-option
            v-for="item in yxs"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div> -->
      <div class="banji">
        <span>选择班级：</span>
        <el-input v-model="bj" placeholder="请输入内容" clearable></el-input>
      </div>

      <div class="number">人数：{{ number }}</div>
      <div class="male">男生：{{ male }}</div>
      <div class="female">女生：{{ female }}</div>

      <div class="number2">计划：{{ number2 }}</div>
      <div class="male2">男生：{{ male2 }}</div>
      <div class="female2">女生：{{ female2 }}</div>

      <button @click="plan">查询</button>
      <button @click="division">分班</button>
    </div>

    <el-table
      v-loading="loading"
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      height="640"
      border
      @selection-change="handleSelectionChange"
      class="table"
    >
      <!-- <el-table-column type="index" label="序号" width="55"> </el-table-column> -->
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="xm" label="姓名" width="110"> </el-table-column>
      <el-table-column prop="ksh" label="考生号" width="200"> </el-table-column>
      <el-table-column prop="xbdm" label="性别" width="80"> </el-table-column>
      <el-table-column prop="lqzy" label="专业名称" width="170">
      </el-table-column>
      <el-table-column prop="tdcj" label="成绩" width="170"> </el-table-column>
      <el-table-column prop="sfdm" label="省份"> </el-table-column>
    </el-table>

    <el-table
      :data="selectData"
      tooltip-effect="dark"
      height="640"
      border
      class="table2"
    >
      <el-table-column type="index" label="序号" width="55"> </el-table-column>
      <el-table-column prop="xm" label="姓名" width="110"> </el-table-column>
      <el-table-column prop="ksh" label="考生号" width="200"> </el-table-column>
      <el-table-column prop="xbdm" label="性别" width="80"> </el-table-column>
      <el-table-column prop="tdcj" label="成绩" width="170"> </el-table-column>
      <el-table-column prop="sfdm" label="省份"> </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { request } from "../../network/request";
export default {
  name: "",
  data() {
    return {
      loading: false,
      jhlb: "",
      jhlbs: [],
      kl: "",
      kls: [],
      zymc: "",
      yx: "",
      yxs: [],
      bj: "",
      number: 0,
      male: 0,
      female: 0,
      number2: 0,
      male2: 0,
      female2: 0,
      tableData: [],
      selectData: [],
    };
  },
  methods: {
    query() {
      this.loading = true;
      request({
        url: "http://118.31.51.131:8081/api/zsxt/fbgl/zswfb",
        method: "post",
        params: {
          zymc: this.zymc,
          token: sessionStorage.getItem("token"),
        },
      }).then((value) => {
        console.log(value);
        this.loading = false;
        this.tableData = value.data;
      });
    },
    reset() {
      this.jhlb = "";
      this.kl = "";
      this.zymc = "";
    },
    plan() {
      request({
        url: "http://118.31.51.131:8081/api/zsxt/fbgl/zfybj",
        method: "post",
        params: {
          bjmc: this.bj,
          token: sessionStorage.getItem("token"),
        },
      }).then((value) => {
        if (value.data == null) {
          alert("未查询到该班级");
        } else {
          console.log(value);
          this.number2 = value.data.bjrs;
          this.male2 = value.data.nsrs;
          this.female2 = value.data.vsrs;
        }
      });
    },
    division() {
      if (
        this.bj != "" &&
        this.number2 != 0 &&
        this.number == this.number2 &&
        this.male == this.male2 &&
        this.female == this.female2
      ) {
        let arr = [];
        for (let item of this.selectData) {
          arr.push({
            bjdh: this.bj,
            fbbz: 1,
            ksh: item.ksh,
            xb: item.xbdm,
            xuehao: "",
          });
        }
        request({
          url: "http://118.31.51.131:8081/api/zsxt/fbgl/sdfb",
          method: "post",
          data: arr,
          params: {
            bjdh: this.bj,
            token: sessionStorage.getItem("token"),
          },
        }).then((value) => {
          console.log(value);
          alert("分班成功");
        });
      }
    },
    handleSelectionChange(val) {
      this.selectData = val;
      this.number = val.length;
      let num1 = 0;
      let num2 = 0;
      val.forEach((item) => {
        if (item.xbdm == "男") {
          num1++;
        } else {
          num2++;
        }
      });
      this.male = num1;
      this.female = num2;
    },
  },
  beforeCreate() {
    if (sessionStorage.getItem("token") == null) {
      this.$router.push("/login");
    } else {
      let token = sessionStorage.getItem("token");
      let length = sessionStorage.getItem("token").length;
      if (token[length - 3] == "0") {
        this.$router.replace("/login");
      }
    }
  },
  components: {},
};
</script>

<style scoped>
.head {
  height: 160px;
  border-bottom: 1px solid #000;
}
/* .head .title {
  line-height: 160px;
  font-size: 20px;
  margin-left: 50px;
} */
.el-input {
  width: 200px;
}
.bank16 {
  margin-left: 16px;
}
.type {
  position: absolute;
  top: 15px;
  left: 25px;
}
.kl {
  position: absolute;
  top: 85px;
  left: 25px;
}
.major {
  position: absolute;
  top: 15px;
  left: 340px;
}
.head button {
  width: 100px;
  height: 45px;
  border: none;
  outline: none;
  cursor: pointer;
  color: #fff;
  background-color: rgb(192, 51, 56);
}
button:active {
  opacity: 0.8;
}
.head button:nth-of-type(1) {
  position: absolute;
  top: 10px;
  left: 680px;
}
.head button:nth-of-type(2) {
  position: absolute;
  top: 85px;
  left: 680px;
}
/* .yuanxi {
  position: absolute;
  top: 15px;
  left: 960px;
} */
.banji {
  position: absolute;
  top: 15px;
  left: 960px;
}
.number {
  position: absolute;
  top: 75px;
  left: 960px;
}
.male {
  position: absolute;
  top: 75px;
  left: 1070px;
}
.female {
  position: absolute;
  top: 75px;
  left: 1180px;
}
.number2 {
  position: absolute;
  top: 115px;
  left: 960px;
}
.male2 {
  position: absolute;
  top: 115px;
  left: 1070px;
}
.female2 {
  position: absolute;
  top: 115px;
  left: 1180px;
}
.head button:nth-of-type(3) {
  position: absolute;
  top: 10px;
  left: 1360px;
}
.head button:nth-of-type(4) {
  position: absolute;
  top: 85px;
  left: 1360px;
}
/* .el-table {
  width: 55%;
  border-right: 1px solid #000;
} */
.table {
  width: 55%;
  border-right: 1px solid #000;
}
.table2 {
  position: absolute;
  left: 55%;
  top: 161px;
  width: 45%;
}
.sdfb ::v-deep .el-table .cell {
  text-align: center;
}
</style>